home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / hopes_babysitting_maze.swf / scripts / __Packages / Classes / bsmEnemy.as next >
Text File  |  2011-08-19  |  3KB  |  107 lines

  1. class Classes.bsmEnemy extends Classes.bsmEntity
  2. {
  3.    var IGNORE_TIMER = 5;
  4.    var SPRAY_TIMER = 4;
  5.    var SOUNDTIMER_MAX = 1;
  6.    function bsmEnemy(t_data, t_levelPath)
  7.    {
  8.       super();
  9.       this.assetID = t_data.assetID;
  10.       this.speed = t_data.speed;
  11.       this.levelPath = t_levelPath;
  12.       this.soundTimer = 0;
  13.       this.currentPoint = this.levelPath.findPoint(t_data.startPoint);
  14.       this.previousPoint = this.currentPoint;
  15.       this.type = t_data.type;
  16.       this.currentFacing = "up";
  17.       this.setToPoint();
  18.       this.targetPoint = {x:this.x,y:this.y};
  19.    }
  20.    function setToPoint()
  21.    {
  22.       var t_point = eval(this.levelPath.hd + ".point" + (this.currentPoint + 1));
  23.       this.x = t_point._x;
  24.       this.y = t_point._y;
  25.    }
  26.    function update(t_elapsed)
  27.    {
  28.       this.xMove = 0;
  29.       this.yMove = 0;
  30.       var _loc10_ = undefined;
  31.       if(this.soundTimer > 0)
  32.       {
  33.          this.soundTimer -= t_elapsed;
  34.       }
  35.       var _loc9_ = false;
  36.       var _loc2_ = undefined;
  37.       var _loc3_ = undefined;
  38.       var _loc4_ = undefined;
  39.       var _loc6_ = undefined;
  40.       var _loc7_ = this.speed * t_elapsed;
  41.       _loc2_ = this.targetPoint.x - this.x;
  42.       _loc3_ = this.targetPoint.y - this.y;
  43.       if(Math.abs(_loc2_) < 1 && Math.abs(_loc3_) < 1)
  44.       {
  45.          this.x = this.targetPoint.x;
  46.          this.y = this.targetPoint.y;
  47.          this.findNextPoint();
  48.          this.update(t_elapsed);
  49.          return undefined;
  50.       }
  51.       var _loc5_ = "up";
  52.       if(_loc2_ >= 1)
  53.       {
  54.          _loc5_ = "right";
  55.       }
  56.       else if(_loc2_ <= -1)
  57.       {
  58.          _loc5_ = "left";
  59.       }
  60.       else if(_loc3_ >= 1)
  61.       {
  62.          _loc5_ = "down";
  63.       }
  64.       this.currentFacing = _loc5_;
  65.       this.mc.gotoAndStop(this.currentFacing);
  66.       _loc6_ = Math.sqrt(_loc2_ * _loc2_ | _loc3_ * _loc3_);
  67.       if(_loc6_ != 0)
  68.       {
  69.          _loc4_ = _loc7_ / _loc6_;
  70.          if(_loc4_ > 1)
  71.          {
  72.             _loc4_ = 1;
  73.          }
  74.          if(this.x != this.targetPoint.x)
  75.          {
  76.             this.xMove = _loc2_ * _loc4_;
  77.          }
  78.          if(this.y != this.targetPoint.y)
  79.          {
  80.             this.yMove = _loc3_ * _loc4_;
  81.          }
  82.       }
  83.    }
  84.    function turnAround()
  85.    {
  86.       this.currentPoint = this.previousPoint;
  87.       var t_mc = eval(this.levelPath.hd + ".point" + (this.currentPoint + 1));
  88.       this.targetPoint = {x:t_mc._x,y:t_mc._y};
  89.    }
  90.    function hitReact()
  91.    {
  92.       if(this.soundTimer <= 0)
  93.       {
  94.          this.levelPath.engine.playSound("puppy");
  95.          this.levelPath.engine.loseScore();
  96.       }
  97.       this.soundTimer = this.SOUNDTIMER_MAX;
  98.    }
  99.    function findNextPoint()
  100.    {
  101.       this.previousPoint = this.currentPoint;
  102.       this.currentPoint = this.levelPath.findAdjacentPoint(this.currentPoint);
  103.       var t_mc = eval(this.levelPath.hd + ".point" + (this.currentPoint + 1));
  104.       this.targetPoint = {x:t_mc._x,y:t_mc._y};
  105.    }
  106. }
  107.